package com.apexcode.orderservice.controller;

import com.apexcode.orderservice.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

/**
 * @ClassName OrderController
 * @Description
 * @Author ZJX
 * @Date 2025/1/10 19:03
 * @Version 1.0
 **/

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/create")
    public String create(){
        String uuid = UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("","order-create","订单信息, ID: "+uuid);
        return "下单成功";
    }

    @RequestMapping("/create2")
    public String create2(){
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderName("商品"+ new Random().nextInt(1000));
        orderInfo.setId(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend("","order-create",orderInfo);
        return "下单成功";
    }
}
